package com.czy.basecommon.utils.base;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;




//fragment的基类  自己新增功能
public abstract class BaseFragment extends Fragment {


    private boolean isFirst = true;

    public Context mContext;





    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = getActivity();

//        Log.d("TAG", "fragment->onCreate");
    }


    @Override
    public void onResume() {
        super.onResume();
        if (isFirst) {
            // 将数据加载逻辑放到onResume()方法中
            initData();

            isFirst = false;
        }


    }

    public abstract void initData();
    /**
     * 跳转页面
     *
     * @param clz 所跳转的目的Activity类
     */
    public void startActivity(Class<?> clz) {
        startActivity(new Intent(getActivity(), clz));
    }

    /**
     * 跳转页面
     *
     * @param clz    所跳转的目的Activity类
     * @param bundle 跳转所携带的信息
     */
    public void startActivity(Class<?> clz, Bundle bundle) {
        Intent intent = new Intent(getActivity(), clz);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        startActivity(intent);
    }

}
